@extends('admin.base')


@section('content')
<!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            <i class="fa fa-calendar"></i>
			会员信息管理
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">后台管理管理</a></li>
            <li class="active">添加管理员</li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">
          <div class="row">
            <!-- right column -->
            <div class="col-md-12">
              <!-- Horizontal Form -->
              <div class="box box-primary">
                <div class="box-header with-border">
                  <h3 class="box-title"><i class="fa fa-plus"></i> 添加管理员信息</h3>
                </div><!-- /.box-header -->
                <!-- form start -->
                <form class="form-horizontal" action="{{url('admin/admin_user/'.$data->id)}}" method="post" id="art_form" enctype="multipart/form-data">
                {{csrf_field()}}
                  <input type="hidden" name="_method" value="put">

                   @if (session('errors'))
                      <div class="mark">
                          <ul>
                                  <li>{{ session('errors') }}</li>
                          </ul>
                      </div>
                  @endif

                  <div class="box-body">
                    <div class="form-group">
                      <label for="inputEmail3" class="col-sm-2 control-label" >账号</label>
                      <div class="col-sm-4">
                        <input type="text" name="username" class="form-control" value="{{$data->username}}" placeholder="账号:6-18位之间的数字字母下划线">
                      </div>
                    </div>
                    
                    <div class="form-group">
                      <label for="inputPassword3" class="col-sm-2 control-label">电话</label>
                      <div class="col-sm-4">
                        <input type="text" name="phone" class="form-control" value="{{$data->phone}}" placeholder="手机号码：11位">
                      </div>
                    </div>
          					<div class="form-group">
                        <label for="inputPassword3" class="col-sm-2 control-label">头像</label>
                        <div class="col-sm-4">
                        <input type="text" name="pic" id="art_thumb"  value="{{old('pic')}}" >
                        <input type="file" name="file_upload" id="file_upload" value=""><br/><br/>
                       <p><img src="{{env('QINIU_DOMAIN')}}{{$data->pic}}" alt="" id="img1" style="width:100px" hidden></p>
                        
                        <script type="text/javascript">
                            $(function () {
                                $("#file_upload").change(function () {
                                    $('img1').show();
                                    uploadImage();
                                });
                            });



                            function uploadImage() {
//                            判断是否有选择上传文件
                                var imgPath = $("#file_upload").val();
                                if (imgPath == "") {
                                    alert("请选择上传图片！");
                                    return;
                                }
                                //判断上传文件的后缀名
                                var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1);
                                if (strExtension != 'jpg' && strExtension != 'gif'
                                    && strExtension != 'png' && strExtension != 'bmp') {
                                    alert("请选择图片文件");
                                    return;
                                }
                                var formData = new FormData($('#art_form')[0]);
                                $.ajax({
                                    type: "POST",
                                    url: "/admin/upload",
                                    data: formData,
                                    async: true,
                                    cache: false,
                                    contentType: false,
                                    processData: false,
                                    success: function(data) {
                                        $('#img1').attr('src','/'+data);
                                        $('#img1').show();
                                        $('#art_thumb').val(data);


                                    },
                                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                                        alert("上传失败，请检查网络后重试");
                                    }
                                });
                            }
                        </script>  
                                </div>
                              </div>
                              
                            </div><!-- /.box-body -->
                            <div class="box-footer">
          				    <div class="col-sm-offset-2 col-sm-1">
          						  <button type="submit" class="btn btn-primary">修改</button>
                      </div>
            					<div class="col-sm-1">
            						<button type="submit" class="btn btn-primary" onclick="history.go(-1)" >返回</button>
            					</div>
                  </div><!-- /.box-footer -->
                </form>
        				<div class="row"><div class="col-sm-12">&nbsp;</div></div>
        				<div class="row"><div class="col-sm-12">
                  <br/>
               
                </div></div>
              </div><!-- /.box -->
       
            </div><!--/.col (right) -->
          </div>   <!-- /.row -->
        </section><!-- /.content -->
        
    @endsection